import { ipcMain } from "electron";
import {
  adbConnectByUsb,
  adbConnectByWifi,
  adbExecReload,
  getDeviceInfoByAdb,
  getDeviceInfoByHdc,
  getDeviceListByAdb,
  getDeviceListByHdc,
  hdcConnectByUsb,
  hdcConnectByWifi,
  hdcExecReload,
  pingIP,
} from "../services/deviceInfo";

import { getAllAppListByHdc } from "../services/getAppList";

import { getSnapShotByHdc } from "../services/snapShot";
import { taskNameGenerator } from "../services/taskNameGenerator";
import {parseCsv} from "../services/parseCsv"

// 获取设备信息
export const startDeviceIpc = (win) => {
  ipcMain.handle("getDeviceListByHdc", async (event) => {
    return await getDeviceListByHdc();
  });

  ipcMain.handle("getDeviceInfoByHdc", async (event, SN) => {
    return await getDeviceInfoByHdc(SN);
  });

  ipcMain.handle("getDeviceListByAdb", async (event) => {
    return await getDeviceListByAdb();
  });

  ipcMain.handle("getDeviceInfoByAdb", async (event, SN) => {
    return await getDeviceInfoByAdb(SN);
  });

  ipcMain.on("freshDeviceList", (e) => win.webContents.send("freshDeviceList"));

  ipcMain.handle("hdcConnectByUsb", async (event, SN) => {
    return await hdcConnectByUsb(SN);
  });

  ipcMain.handle("hdcConnectByWifi", async (event, SN, Ip) => {
    return await hdcConnectByWifi(SN, Ip);
  });

  ipcMain.handle("hdcExecReload", async (event, SN, Ip) => {
    return await hdcExecReload(SN, Ip);
  });

  ipcMain.handle("adbConnectByUsb", async (event, SN) => {
    return await adbConnectByUsb(SN);
  });

  ipcMain.handle("adbConnectByWifi", async (event, SN, Ip) => {
    return await adbConnectByWifi(SN, Ip);
  });

  ipcMain.handle("adbExecReload", async (event, SN, Ip) => {
    return await adbExecReload(SN, Ip);
  });

  ipcMain.handle("pingIP", async (event, Ip) => {
    return await pingIP(Ip);
  });
};

export const startAppListIpc = (win) => {
  ipcMain.handle("getAllAppListByHdc", async (event, SN) => {
    return await getAllAppListByHdc(SN);
  });
};

export const startTaskNameGenerator = (win) => {
  ipcMain.handle("taskNameGenerator", async (event, SN, taskType) => {
    return await taskNameGenerator(SN, taskType);
  });
};

export const startSnapShot = (win) => {
  ipcMain.handle(
    "getSnapShotByHdc",
    async (event, taskName, SN, OS, testType) => {
      return await getSnapShotByHdc(taskName, SN, OS, testType);
    }
  );
};

export const startParseCsv = (win) => {
  console.log("1111111******111")
  ipcMain.handle(
    "parseCsv",
    async (event) => {
      console.log("22222******222")
      return await parseCsv();
    }
  );
};